package ma.co.ba.BusinessApplications.presentation.controllers;

import ma.co.ba.BusinessApplications.business.utilisateurs.UtilisateurBusiness;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

	@Autowired
	UtilisateurBusiness utilisateurBusiness;
	
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String loginPage(ModelMap model,
		@RequestParam(value = "error", required = false) String error,
		@RequestParam(value = "logout", required = false) String logout) {
 
		
		if (error != null) {
			model.addAttribute("error", "Invalid username and password!");
		}
 
		if (logout != null) {
			model.addAttribute("msg", "You've been logged out successfully.");
		}
		
 		return "login";
 	}

	/* GET & POST Handler Example
	 *
	 * @RequestMapping(method = RequestMethod.GET) public String
	 * utilisateursPage(ModelMap model,
	 * 
	 * @ModelAttribute("newUser") Utilisateur newUser) { // // return form view
	 * return "utilisateurs"; }
	 * 
	 * 
	 * @RequestMapping(method = RequestMethod.POST) public String
	 * processSubmit(@ModelAttribute("newUser") Utilisateur newUser,
	 * BindingResult result, SessionStatus status) {
	 * 
	 * 
	 * return null; }
	 */
}